<?php
/**
 * Created by PhpStorm.
 * User: 86158
 * Date: 2021/6/14
 * Time: 18:51
 */

namespace App\Models\activity;


use App\Models\Model;
use App\Models\User;

class ActivityMember extends Model
{
    protected $fillable = [
        'activity_id',
        'user_id',
        'status'
    ];

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id');
    }

    /**
     * 获取单活动用户列表
     * @param $activity_id
     * @return array
     */
    public function getList($activity_id)
    {
        $map = [
            'activity_id' => $activity_id,
            'status'    => 1
        ];
        $data = self::where($map)
            ->select(['user_id'])
            ->with('user')
            ->get()
            ->toArray();
        return $data;
    }

    /**
     * 判断是否参与此活动
     * @param $activityId
     * @param $user_id
     * @return bool
     */
    public function check($activityId,$user_id)
    {
        $where = [
            'activity_id' => $activityId,
            'user_id'     => $user_id,
            'status'      => 1
        ];
        $data = self::where($where)->first();
        return $data ? true : false;
    }
}